package com.wolfsea.viewpagerrecyclerviewpageing
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.viewpager.widget.ViewPager
import com.wolfsea.viewpagerrecyclerviewpageing.model.ModelHomeEntrance
import com.wolfsea.viewpagerrecyclerviewpageing.pagemenulibrary.holder.AbstractHolder
import com.wolfsea.viewpagerrecyclerviewpageing.pagemenulibrary.holder.HomeEntranceHolderCreatorImpl
import com.wolfsea.viewpagerrecyclerviewpageing.pagemenulibrary.holder.HomeEntranceViewHolder
import com.wolfsea.viewpagerrecyclerviewpageing.pagemenulibrary.holder.PageMenuViewHolderCreator
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    private var homeEntrances = mutableListOf<ModelHomeEntrance>()

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initData()
        init()
    }

    private fun init() {

        page_menu.setPageDataSet(homeEntrances, HomeEntranceHolderCreatorImpl())
        main_home_entrance_indicator.setIndicatorCount(page_menu.pageCount)
        page_menu.setOnPageListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {}

            override fun onPageSelected(position: Int) {
                main_home_entrance_indicator.setCurrentIndicator(position)
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
    }

    private fun initData() {
        homeEntrances.add(ModelHomeEntrance("美食", R.mipmap.ic_category_0))
        homeEntrances.add(ModelHomeEntrance("电影", R.mipmap.ic_category_1))
        homeEntrances.add(ModelHomeEntrance("酒店住宿", R.mipmap.ic_category_2))
        homeEntrances.add(ModelHomeEntrance("生活服务", R.mipmap.ic_category_3))

        homeEntrances.add(ModelHomeEntrance("KTV", R.mipmap.ic_category_4))
        homeEntrances.add(ModelHomeEntrance("旅游", R.mipmap.ic_category_5))
        homeEntrances.add(ModelHomeEntrance("学习培训", R.mipmap.ic_category_6))
        homeEntrances.add(ModelHomeEntrance("汽车服务", R.mipmap.ic_category_7))

        homeEntrances.add(ModelHomeEntrance("摄影写真", R.mipmap.ic_category_8))
        homeEntrances.add(ModelHomeEntrance("休闲娱乐", R.mipmap.ic_category_10))
        homeEntrances.add(ModelHomeEntrance("丽人", R.mipmap.ic_category_11))
        homeEntrances.add(ModelHomeEntrance("运动健身", R.mipmap.ic_category_12))

        homeEntrances.add(ModelHomeEntrance("大保健", R.mipmap.ic_category_13))
        homeEntrances.add(ModelHomeEntrance("团购", R.mipmap.ic_category_14))
        homeEntrances.add(ModelHomeEntrance("景点", R.mipmap.ic_category_16))
        homeEntrances.add(ModelHomeEntrance("全部分类", R.mipmap.ic_category_15))

        homeEntrances.add(ModelHomeEntrance("生活服务", R.mipmap.ic_category_3))
        homeEntrances.add(ModelHomeEntrance("KTV", R.mipmap.ic_category_4))
        homeEntrances.add(ModelHomeEntrance("旅游", R.mipmap.ic_category_5))
        homeEntrances.add(ModelHomeEntrance("学习培训", R.mipmap.ic_category_6))

        homeEntrances.add(ModelHomeEntrance("摄影写真", R.mipmap.ic_category_8))
        homeEntrances.add(ModelHomeEntrance("休闲娱乐", R.mipmap.ic_category_10))
        homeEntrances.add(ModelHomeEntrance("丽人", R.mipmap.ic_category_11))
        homeEntrances.add(ModelHomeEntrance("运动健身", R.mipmap.ic_category_12))

        homeEntrances.add(ModelHomeEntrance("美食", R.mipmap.ic_category_0))
        homeEntrances.add(ModelHomeEntrance("电影", R.mipmap.ic_category_1))
        homeEntrances.add(ModelHomeEntrance("团购", R.mipmap.ic_category_14))
        homeEntrances.add(ModelHomeEntrance("景点", R.mipmap.ic_category_16))

        homeEntrances.add(ModelHomeEntrance("KTV", R.mipmap.ic_category_4))
        homeEntrances.add(ModelHomeEntrance("旅游", R.mipmap.ic_category_5))
        homeEntrances.add(ModelHomeEntrance("丽人", R.mipmap.ic_category_11))
        homeEntrances.add(ModelHomeEntrance("运动健身", R.mipmap.ic_category_12))
    }

}